package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.common.R;
import com.qf.java2201.mapper.KindMapper;
import com.qf.java2201.pojo.Kind;
import com.qf.java2201.service.KindService;
import com.qf.java2201.vo.BarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author wxf
 * @Date 2022/4/26 16:47
 **/

@Service("kindService")
public class KindServiceImpl implements KindService {

    @Autowired
    private KindMapper kindMapper;

    @Override
    public PageVo<Kind> getPageData(Map<String, Object> params) {
        String page = (String) params.get("page");
        String limit = (String) params.get("limit");

        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));

        List<Kind> kinds = kindMapper.selectByParams(params);

        PageInfo<Kind> kindPageInfo = new PageInfo<>(kinds);

        PageVo<Kind> kindPageVo = new PageVo<>();

        kindPageVo.setData(kindPageInfo.getList());
        kindPageVo.setCode(0);
        kindPageVo.setCount(kindPageInfo.getTotal());

        kindPageVo.setMsg("分类列表数据");

        return kindPageVo;
    }

    @Override
    public int addFlowerKind(Kind kind) {
        return kindMapper.addFlowerKind(kind);
    }

    @Override
    public int deleteFlower(int id) {
        return kindMapper.deleteFlower(id);
    }

    @Override
    public int updateFlower(Kind kind) {
        return kindMapper.updateFlower(kind);
    }

    @Override
    public List<Kind> flowerPageData(Kind kind) {
        return kindMapper.flowerPageData(kind);
    }

    @Override
    public List<BarVo> dateBarData() {
        return kindMapper.dateBarData();
    }

    @Override
    public List<Kind> selectList(Kind kind) {
        return kindMapper.selectList(kind);
    }

    @Override
    public int deleteByIds(ArrayList<Integer> list) {
        return kindMapper.deleteByIds(list);
    }
}
